package com.itcoon.system.service.impl;/**
 * @author Athric Yu
 * 2024/12/19
 **/

import com.itcoon.cloud.framework.mybatis.service.XServiceImpl;
import com.itcoon.cloud.framework.transform.Transformer;
import com.itcoon.system.entity.AdminUserDO;
import com.itcoon.system.mapper.AdminUserMapper;
import com.itcoon.system.service.AdminUserService;
import com.itcoon.system.web.vo.AdminUserCreateReqVO;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

/**
 *
 *
 * @author Athric Yu
 * 2024/12/19
 **/
@Service
public class AdminUserServiceImpl extends XServiceImpl<AdminUserMapper, AdminUserDO> implements AdminUserService {

    private final PasswordEncoder passwordEncoder;

    public AdminUserServiceImpl(AdminUserMapper baseMapper, PasswordEncoder passwordEncoder) {
        super(baseMapper);
        this.passwordEncoder = passwordEncoder;
    }


    @Override
    public void register(AdminUserCreateReqVO command) {
        AdminUserDO user = Transformer.to(AdminUserDO.class).apply(command)
                .setAt(AdminUserDO::getPassword, passwordEncoder.encode(command.getPassword()))
                .convert();

        getBaseMapper().insert(user);
    }
}
